package skiree.host.abetsy.api.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import skiree.host.abetsy.api.service.AnimeService;
import skiree.host.abetsy.api.vessel.Result;
import skiree.host.abetsy.model.LocalAnime;

import javax.annotation.Resource;

@Controller
@CrossOrigin
@RequestMapping("/api/private/v1")
public class AnimeController {

    @Resource
    private AnimeService animeService;

    @GetMapping("/anime/list")
    @ResponseBody
    public Result animeList(@RequestParam(required = false, defaultValue = "") String query,
                            @RequestParam(required = false, defaultValue = "1") int pageNum,
                            @RequestParam(required = false, defaultValue = "9") int pageSize) {
        return animeService.list(query, pageNum, pageSize);
    }

    @PostMapping("/anime/add")
    @ResponseBody
    public Result animeAdd(@RequestBody LocalAnime localAnime) {
        return animeService.add(localAnime);
    }

    @PostMapping("/anime/edit")
    @ResponseBody
    public Result animeEdit(@RequestBody LocalAnime localAnime) {
        return animeService.edit(localAnime);
    }

    @GetMapping("/anime/delete/{id}")
    @ResponseBody
    public Result animeDelete(@PathVariable("id") int id) {
        animeService.delete(id);
        return Result.success(null);
    }

    @GetMapping("/anime/increment/{id}")
    @ResponseBody
    public Result animeIncrement(@PathVariable("id") int id) {
        animeService.increment(id);
        return Result.success(null);
    }

    @GetMapping("/anime/complete/{id}")
    @ResponseBody
    public Result animeComplete(@PathVariable("id") int id) {
        animeService.complete(id);
        return Result.success(null);
    }

}
